package com.lin.jdk.juc.lock;

public class StampLockProp {

    /** The number of bits to use for reader count before overflowing */
    private static final int LG_READERS = 7; // 127 readers

    // Values for lock state and stamp operations
    private static final long RUNIT = 1L;
    private static final long WBIT  = 1L << LG_READERS;
    private static final long RBITS = WBIT - 1L;
    private static final long RFULL = RBITS - 1L;
    private static final long ABITS = RBITS | WBIT;
    private static final long SBITS = ~RBITS; // note overlap with ABITS
    // not writing and conservatively non-overflowing
    private static final long RSAFE = ~(3L << (LG_READERS - 1));
    private static final long ORIGIN = WBIT << 1;
    static final int CANCELLED = 0x80000000; // must be negative

    public static void main(String[] args) {
        System.out.println("Integer.toBinaryString(WBIT) = " + Long.toBinaryString(WBIT));
        System.out.println("Integer.toBinaryString(RBITS) = " + Long.toBinaryString(RBITS));
        System.out.println("Integer.toBinaryString(RFULL) = " + Long.toBinaryString(RFULL));
        System.out.println("Integer.toBinaryString(ABITS) = " + Long.toBinaryString(ABITS));
        System.out.println("Integer.toBinaryString(SBITS) = " + Long.toBinaryString(SBITS));
        System.out.println("Integer.toBinaryString(RSAFE) = " + Long.toBinaryString(RSAFE));
        System.out.println("Integer.toBinaryString(ORIGIN) = " + Long.toBinaryString(ORIGIN));
        System.out.println("Integer.toBinaryString(CANCELLED) = " + Long.toBinaryString(CANCELLED));
        System.out.println("-------------------------------");
    }

}
